package com.atguigu.thread;

import java.util.concurrent.TimeUnit;

public class Test8syn {



    public static void main(String[] args) {
        Phone phone1 = new Phone();
        Phone phone2 = new Phone();
        new Thread(()->{
            try {
                phone1.sendEmail();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"A").start();

        System.out.println("main-----");
        new Thread(()->{
            //phone1.sendSms();
//            phone2.sendSms();
            phone1.call();
        },"B").start();
    }
}

class Phone{
    public synchronized void sendEmail() throws InterruptedException {
        TimeUnit.SECONDS.sleep(4);
        System.out.println("sendEmail");
    }
//    public static synchronized void sendSms(){
//        System.out.println("sendSms");
//    }
//    public synchronized void sendEmail() throws InterruptedException {
//        TimeUnit.SECONDS.sleep(4);
//        System.out.println("sendEmail");
//    }
    public synchronized void sendSms(){
        System.out.println("sendSms");
    }
    public void call(){
        System.out.println("call");
    }
}